class @ScrollPagingView extends CustomView

    initialize: ->
        super
        console.log "ScrollPagination initialize"
        $(window).on("scroll", =>
            if @isEnabled
               mayLoadContent = ($(document).scrollTop() + $(window).height() >= $(@el).height())
               if mayLoadContent
                   @startLoading()
        )

    heightOffset: 355
    isEnabled: true

    renewScrolling: ->
        @isEnabled = true

    startLoading: ->
        $(@el).append("<div class='scroll-loading'></div>")
        @isEnabled = false;
        $.ajax(
            type: 'POST'
            url: @model.url()
            success: (data) =>
                @model.set("Page", @model.get("Page") + 1, silent: true)
                @afterLoad(data)
                if data.length
                    @isEnabled = true
            complete: =>
                @removeScrollLoading()
        )

    removeScrollLoading: ->
        $(@el).find(".scroll-loading").remove()